/*
  获取公司信息
*/
import { changeInputValue } from '../../utils.js'
// function changeInputValue(ele, val) {
//   ele.value = val;
//   var event = document.createEvent('HTMLEvents');
//   event.initEvent("input", true, true);
//   event.eventType = 'message';
//   ele.dispatchEvent(event);
// }

function autoInputAccount({ companyInfo }) {
  console.log(companyInfo);
  if (location.href.includes('https://etax.yunnan.chinatax.gov.cn')) {
    let loginopen = $('#loginopen')
    if (loginopen.text().includes('登录') && !loginopen.attr('href')) {
      loginopen.click();
    }
    return;
  }

  if (location.href.includes('https://tpass.yunnan.chinatax.gov.cn:8443/')) {
    let timer = setInterval(() => {
      const { nationalTaxId, nationalTaxAccount, nationalTaxPass } = companyInfo;
      if (!document.querySelector('input[placeholder="统一社会信用代码/纳税人识别号"]')) {
        return false;
      }
      changeInputValue(document.querySelector('input[placeholder="统一社会信用代码/纳税人识别号"]'), nationalTaxId);
      changeInputValue(document.querySelector('input[placeholder="居民身份证号码/手机号码/用户名"]'), nationalTaxAccount);
      changeInputValue(document.querySelector('input[placeholder="个人用户密码"]'), nationalTaxPass);

      clearInterval(timer);
      timer = null;
    }, 1000);

  }
}

export {
  autoInputAccount
}